package com.example.administrator.myapplication.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.administrator.myapplication.MyApplication;


/**
 * SharedPreFerences存储与读取统一管理
 *
 *
 */
public class SharedPreFerencesTools {
	public final static String preferencesName = "PublicData";

	/**
	 * 获取UserID
	 *
	 * @return
	 */
	public static String getUserId() {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		return sp.getString("userId", "");

	}

	/**
	 * 设置UserID
	 *
	 * @param userId
	 */
	public static void setUserId(String userId) {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor edit = sp.edit();
		edit.putString("userId", userId);

		edit.commit();
	}
	/**
	 * 获取UserIP
	 *
	 * @return
	 */
	public static String getUserIP() {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		return sp.getString("userIp","");

	}

	/**
	 * 设置UserIp
	 *
	 * @param userIp
	 */
	public static void setUserIP(String userIp) {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor edit = sp.edit();
		edit.putString("userIp", userIp);

		edit.commit();
	}
	/**
	 * 获取UserPhone
	 *
	 * @return
	 */
	public static String getUserPhone() {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		return sp.getString("userPhone","");

	}

	/**
	 * 设置UserPhone
	 *
	 * @param userPhone
	 */
	public static void setUserPhone(String userPhone) {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor edit = sp.edit();
		edit.putString("userPhone", userPhone);

		edit.commit();
	}
	/**
	 * 获取是否记住密码
	 *
	 * @return
	 */
	public static String getTestStr() {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		return sp.getString("password","");

	}

	/**
	 * 设置UserPhone
	 *
	 * @param password
	 */
	public static void setTestStr(String password) {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor edit = sp.edit();
		edit.putString("password", password);

		edit.commit();
	}
	/**
	 * 获取Userpw
	 *
	 * @return
	 */
	public static String getMemberPw() {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		return sp.getString("member_pw", "");

	}

	/**
	 * 设置Usermima
	 *
	 * @param member_pw
	 */
	public static void setMemberPw(String member_pw) {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor edit = sp.edit();
		edit.putString("member_pw", member_pw);

		edit.commit();
	}
	/**
	 * 获取UserName
	 *
	 * @return
	 */
	public static String getMemberName() {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		return sp.getString("membername", "");

	}

	/**
	 * 设置UserPhone
	 *
	 * @param membername
	 */
	public static void setMemberName(String membername) {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor edit = sp.edit();
		edit.putString("membername", membername);

		edit.commit();
	}
	/**
	 * 获取用户详细地址
	 *
	 * @return
	 */
	public static String getUserAddress() {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		return sp.getString("userAddress", "");

	}

	/**
	 * 设置用户详细地址
	 *
	 * @param userAddress
	 */
	public static void setUserAddress(String userAddress) {
		SharedPreferences sp;
		sp = MyApplication.getContext().getSharedPreferences(preferencesName,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor edit = sp.edit();
		edit.putString("userAddress", userAddress);

		edit.commit();
	}
}